from ..extensions import db
from datetime import datetime

class Announcement(db.Model):
    __tablename__ = 'announcements'
    
    id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"), primary_key=True, autoincrement=True, comment='公告ID')
    title = db.Column(db.String(200), nullable=False, comment='公告标题')
    content = db.Column(db.Text, nullable=False, comment='公告内容')
    announcement_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='公告时间')
    publisher = db.Column(db.String(100), nullable=False, comment='发布机构')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='记录创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'title': self.title,
            'content': self.content,
            'announcement_time': str(self.announcement_time),
            'publisher': self.publisher,
            'created_at': str(self.created_at)
        }